import 'package:amoy_ticket/widget/splash/splash_logic.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashPage extends StatelessWidget {
  SplashPage({Key? key}) : super(key: key);

  final splashLogic = Get.put(SplashLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          _buildAdWidget(),
          Positioned(
              top: 10 + MediaQuery.of(context).padding.top,
              right: 20,
              child: GetBuilder<SplashLogic>(
                builder: (logic) => Container(
                  alignment: Alignment.bottomRight,
                  child: InkWell(
                    onTap: () {
                      logic.toNextPage();
                    },
                    child: new Container(
                      padding:
                          EdgeInsets.symmetric(horizontal: 15, vertical: 8),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(40),
                        color: Colors.black.withAlpha(100),
                      ),
                      child: new Text(
                        "${logic.count} | 跳过",
                        style:
                            new TextStyle(fontSize: 14.0, color: Colors.white),
                      ),
                    ),
                  ),
                ),
              ))
        ],
      ),
    );
  }

  //广告页面
  Widget _buildAdWidget() {
    return GestureDetector(
      onTap: () {},
      child: new Container(
        alignment: Alignment.center,
        child: CachedNetworkImage(
          width: double.infinity,
          fit: BoxFit.cover,
          imageUrl:
              'https://amoy-ticket.oss-cn-nanjing.aliyuncs.com/images/coming_soon_bg/image4.jpg',
          errorWidget: (context, url, error) => _buildSplashBg(),
          placeholder: (context, url) => SizedBox.shrink(),
        ),
      ),
    );
  }

  //创建广告的默认背景图
  Widget _buildSplashBg() {
    return Center(
        child: Image.asset(
      'assets/images/people_bg.png',
      fit: BoxFit.fitWidth,
      height: Get.height,
    ));
  }
}
